package com.alibaba.shopping_seckill_service;

import cn.hutool.bloomfilter.BitMapBloomFilter;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;


@EnableScheduling // 开启定时任务
@EnableDiscoveryClient
@EnableDubbo
@RefreshScope
@MapperScan("com.alibaba.shopping_seckill_service.mapper")
@SpringBootApplication
public class ShoppingSeckillServiceApplication {

    public static void main(String[] args) {

        SpringApplication.run(ShoppingSeckillServiceApplication.class, args);
    }

    // 开启分页插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    // 注入布隆过滤器
    @Bean
    public BitMapBloomFilter bitMapBloomFilter(){
        // 设置布隆过滤器大小为10000
        BitMapBloomFilter filter = new BitMapBloomFilter(1000);
        return filter;
    }
}
